package faceb.server.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet{

	@Override
	public void init() throws ServletException {
		System.out.println("servlet init");
		super.init();
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	
		resp.setCharacterEncoding("utf-8");
		OutputStream os = resp.getOutputStream();
		String filename = URLEncoder.encode("《白帽子讲Web安全》.(白帽子讲Web安全).[PDF].@ckook.pdf", "utf-8");
		resp.addHeader("Content-Disposition", "attachment;filename="+filename);
		
		FileInputStream fis =new FileInputStream(new File("D:/《白帽子讲Web安全》.(白帽子讲Web安全).[PDF].@ckook.pdf"));
		byte []b =new byte[fis.available()];
		fis.read(b);
		os.write(b);
		fis.close();
		os.close();
	}
}
